/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.defaultCode;

import edu.wpi.first.wpilibj.AnalogChannel;

/**
 *
 * @author SteveS
 */
public class AnalogLimitSwitch {

    private AnalogChannel channel;
    private boolean prevSwitchState;

    private double LOW_VOLTAGE = 2.0;
    private double HIGH_VOLTAGE = 3.0;

    public AnalogLimitSwitch(AnalogChannel channel )
    {
        this.channel = channel;
        prevSwitchState = false;
    }

    public boolean readSwitch( )
    {
        double voltage = channel.getVoltage();
        boolean retval = prevSwitchState;
        if ( voltage < LOW_VOLTAGE )
        {
            retval = true;
        }
        else if ( voltage > HIGH_VOLTAGE )
        {
            retval = false;
        }
        
        return retval;
    }
}
